﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2021_5_10
{
    class Program
    {
        static void Main(string[] args)
        {
            YanghuiTriangle();1212
            //2. 在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息；然后在主方法调用输出；
            Users user1 = new Users();
            user1.Account = "202105123";
            user1.UserName = "testUser";
            user1.Password = "114514";

            user1.UserMsg();

            //在 Main 方法中创建一个字符串类型的数组，并存入 5 个值，然后将数组中下标是偶数的元素输出。
            string[] arr = { "ab", "cd", "ef", "gh", "xy" };

            Console.WriteLine("下标为偶数的元素有：");
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                if (i % 2 == 0)
                {
                    Console.Write(arr[i] + " ");
                }
            }
            Console.WriteLine();

        }

        //用户输入正方形边长，用*打印出实心正方形。
        static void PrintSqure()
        {
            Console.WriteLine("请输入正方形的边长：");
            int side = Convert.ToInt32(Console.ReadLine());

            string [,] squre = new string[side, side];

            for (int i = 0; i < squre.GetLength(0); i++)
            {
                for (int j = 0; j < squre.GetLength(1); j++)
                {
                    squre[i,j] = "* ";
                }
            }

            for (int i = 0; i < squre.GetLength(0); i++)
            {
                for (int j = 0; j < squre.GetLength(1); j++)
                {
                    Console.Write(squre[i,j]);
                }
                Console.WriteLine();
            }

        }
        //乘法表
        static void PrintMultiplyTable() 
        {
            string[,] table = new string[9,9];

            for (int i = 0; i < table.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    table[i,j] = (i+1) + "*" + (j+1) + "=" + (i+1) * (j+1) + "\t";
                }
            }

            for (int i = 0; i < table.GetLength(0); i++)
            {
                for (int j = 0; j < table.GetLength(1); j++)
                {
                    Console.Write(table[i,j]);
                }
                Console.WriteLine();
            }
        }
        //用户输入正方形边长，用*打印出空心正方形。
        static void PrintBorderSqure() 
        {
            Console.WriteLine("请输入空心正方形的边长：");
            int side = Convert.ToInt32(Console.ReadLine());

            string[,] borderSqure = new string[side, side];

            for (int i = 0; i < borderSqure.GetLength(0); i++)
            {
                for (int j = 0; j < borderSqure.GetLength(1); j++)
                {
                    if (i == 0 || i == borderSqure.GetLength(0) - 1)
                    {
                        borderSqure[i, j] = "* ";
                    }
                    else if (j == 0 || j == borderSqure.GetLength(1) - 1)
                    {
                        borderSqure[i, j] = "* ";
                    }
                    else
                    {
                        borderSqure[i, j] = "  ";
                    }
                }

            }
                for (int i = 0; i < side; i++)
                {
                    for (int j = 0; j < side; j++)
                    {
                        Console.Write(borderSqure[i,j]);
                    }
                    Console.WriteLine();
                }
        }

        //打印菱形
        static void rhombus() 
        {
            Console.WriteLine("请输入菱形的边长：");
            int side = Convert.ToInt32(Console.ReadLine());
            string[,] rhombus = new string[side * 2 -1, side * 2 -1];

            for (int i = 0; i < rhombus.GetLength(0); i++)
            {
                for (int j = 0; j < rhombus.GetLength(1); j++)
                {
                    if (i < side)
                    {
                        if (j >= side - 1 - i && j <= side - 1 + i)
                        {
                            rhombus[i, j] = " *";
                        }
                        else
                        {
                            rhombus[i, j] = "  ";
                        }
                    }
                    else {
                        rhombus[i, j] = rhombus[side * 2 - 1 - i - 1, j];
                    }

                }
            }

            for (int i = 0; i < rhombus.GetLength(0); i++)
            {
                for (int j = 0; j < rhombus.GetLength(1); j++)
                {
                    Console.Write(rhombus[i,j]);
                }
                Console.WriteLine();
            }
        }

        //十行杨辉三角形
        static void YanghuiTriangle()
        {
            Console.WriteLine("请输入要打印的行数：");
            int line = int.Parse(Console.ReadLine());
            int[,] Yang = new int[line, line];

            for (int i = 0; i < Yang.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    if (j == 0 || j == i)
                    {
                        Yang[i, j] = 1;
                    }
                    else {
                        Yang[i, j] = Yang[i - 1, j] + Yang[i - 1, j - 1];
                    }
                }
            }

            for (int i = 0; i < Yang.GetLength(0); i++)
            {
                for (int j = 0; j < Yang.GetLength(1); j++)
                {
                    if (Yang[i,j] != 0) {
                        Console.Write(Yang[i, j] + "\t");
                    }
                }
                Console.WriteLine();
            }

        }

        //用户输入正方形边长，用*打印出空心正方形。
        static void BorderBlock() {
            Console.WriteLine("请输入空心正方形的边长:");
            int side = Convert.ToInt32(Console.ReadLine());

            string[,] blockBorder = new string[side,side];

            for (int i = 0; i < blockBorder.GetLength(0); i++)
            {
                for (int j = 0; j < blockBorder.GetLength(1); j++)
                {
                    if (i == 0 || i == side - 1)
                    {
                        blockBorder[i, j] = "* ";
                    }
                    else {
                        if (j == 0 || j == side - 1)
                        {
                            blockBorder[i, j] = "* ";
                        }
                        else {
                            blockBorder[i, j] = "  ";
                        }
                    }
                }
            }

            for (int i = 0; i < blockBorder.GetLength(0); i++)
            {
                for (int j = 0; j < blockBorder.GetLength(1); j++)
                {
                    Console.Write(blockBorder[i,j]);
                }
                Console.WriteLine();
            }
        }

        //如果一个数组保存元素是有序的（从大到小），向这个数组中插入一个数，使得插入后的数组元素仍然保持有序。
        static void SortArrays() {
            int[] arr = { 38, 25, 13, 10, 8 };

            Console.WriteLine("原数组为：");
            foreach (var item in arr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Console.WriteLine("请输入你要向数组中插入的数：");
            int num = Convert.ToInt32(Console.ReadLine());

            int[] sortArr = new int[arr.Length + 1];

            for (int i = 0; i < sortArr.Length; i++)
            {
                if (i > arr.Length - 1)
                {
                    sortArr[i] = num;
                    break;
                }
                else 
                {
                    sortArr[i] = arr[i];
                }
            }

            Array.Sort(sortArr);
            Array.Reverse(sortArr);

            Console.WriteLine("整理后的数组为：");
            foreach (var item in sortArr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }

    }
}
